﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KP_CommonLibrary.KP_CoreUI;
using KP_CommonLibrary.KP_CommonControls;
using KP_CommonLibrary;
using KEEPER_BRR_13dotNET.BusinessLogic;

namespace KEEPER_BRR_13dotNET.Presentation
{
    public partial class FrmE_AddGiayTo2HS : KP_CommonLibrary.KP_CoreUI.KP_EditListItem
    {
        public string HoSoRec { get; set; }
        public FrmE_AddGiayTo2HS()
        {
            InitializeComponent();
        }
        public override void InitData(System.Data.DataRow row)
        {
            row["Co"] = true;
            row["Ghi_Chu"] = "";
            row["Stt_Rec"] = HoSoRec;
            row["Bat_Buoc"] = false;
            base.InitData(row);
        }
        public override void CustomWriteData(DataRow row)
        {
            
            base.CustomWriteData(row);
        }
        public override void LoadDependencyData()
        {
            BL_KPDmLoaiGt BLDmLoaiGt = new BL_KPDmLoaiGt();
            cbMa_LoaiGt.DataSource = BLDmLoaiGt.Select();
            BL_KPDmTcGt BLDmTcGt = new BL_KPDmTcGt();
            cbMa_TcGt.DataSource = BLDmTcGt.Select();
            base.LoadDependencyData();
        }
        public override void SaveAndNew()
        {
            string state = "";
            try
            {

                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Kết thúc cập nhật\n";
                    EndEdit();
                    ParentBinding.Refresh();
                    state = "Lưu dữ liệu\n";                 
                    FormState = FormState.Unspecified;
                    AddNew(ParentBinding);
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
        public override void SaveAndClose()
        {
            string state = "";
            try
            {

                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Kết thúc cập nhật\n";
                    EndEdit();
                    ParentBinding.Refresh();
                    state = "Lưu dữ liệu\n";
                    //if (FormState == FormState.Insert)
                    //{
                    //    Business.Insert(CurrentRow);

                    //}
                    //else
                    //{
                    //    Business.Update(CurrentRow);
                    //}
                    // CurrentRow.AcceptChanges();
                    FormState = FormState.Unspecified;
                    Close();
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
    }
}
